import wx


class SettingWindow(wx.Dialog):
    def __init__(self, parent, title):
        super(SettingWindow, self).__init__(parent, title=title, size=(380, 360))
        self.grid_sizer1 = {}
        self.init_ui()
        self.config_data = parent.config_data
        self.init_data(self.config_data.cueSetting)

    def init_ui(self):
        self.Centre()
        panel = wx.Panel(self)
        grid_sizer1 = wx.FlexGridSizer(cols=2, vgap=10, hgap=1)
        self.firstClassNumCtrl = wx.SpinCtrl(panel, value='10', min=0, max=50)
        label = wx.StaticText(panel, label="运动想象次数：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.firstClassNumCtrl, 0, wx.ALL, 5)

        self.secondClassNumCtrl = wx.SpinCtrl(panel, value='10', min=0, max=50)
        label = wx.StaticText(panel, label="放松模式次数：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.secondClassNumCtrl, 0, wx.ALL, 5)

        self.baselineCtrl = wx.SpinCtrl(panel, value='5', min=0, max=20)
        label = wx.StaticText(panel, label="准备时长（秒）：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.baselineCtrl, 0, wx.ALL, 5)

        self.waitCueCtrl = wx.SpinCtrl(panel, value='2', min=0, max=10)
        label = wx.StaticText(panel, label="提示间隔（秒）：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.waitCueCtrl, 0, wx.ALL, 5)

        self.dispCueCtrl = wx.SpinCtrl(panel, value='5', min=0, max=20)
        label = wx.StaticText(panel, label="运动想象/放松（秒）：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.dispCueCtrl, 0, wx.ALL, 5)

        self.repeatCueCtrl = wx.SpinCtrl(panel, value='2', min=0, max=4)
        label = wx.StaticText(panel, label="循环(次）：")
        grid_sizer1.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer1.Add(self.repeatCueCtrl, 0, wx.ALL, 5)

        # auditory cue 听觉提示复选框
        self.auditoryCue = wx.CheckBox(panel, -1, "听觉提示")
        grid_sizer1.Add(self.auditoryCue, 0, wx.ALL | wx.ALIGN_CENTER, 5)

        self.submitBtn = wx.Button(panel, label="提交", size=(100, 27))
        self.submitBtn.Bind(wx.EVT_BUTTON, self.on_submit)
        grid_sizer1.Add(self.submitBtn, 0, wx.ALL, 5)

        grid_sizer = wx.FlexGridSizer(cols=1, vgap=1, hgap=1)
        grid_sizer.Add(grid_sizer1, 0, wx.ALL, 5)
        panel.SetSizerAndFit(grid_sizer)
        panel.Center()
        self.Fit()

    def on_submit(self, event):
        self.Close()  # 关闭窗体

    # 从窗体获取数据
    def get_value(self):
        self.config_data.cueSetting = {
            'firstClassNum': self.firstClassNumCtrl.GetValue(),
            'secondClassNum': self.secondClassNumCtrl.GetValue(),
            'baselineDuration': self.baselineCtrl.GetValue(),
            'waitCueDuration': self.waitCueCtrl.GetValue(),
            'dispCueDuration': self.dispCueCtrl.GetValue(),
            'repeatCue': self.repeatCueCtrl.GetValue(),
            'auditoryIsChecked': self.auditoryCue.IsChecked()
        }
        return self.config_data

    # 界面初始化
    def init_data(self, cueSettingData):
        self.firstClassNumCtrl.SetValue(cueSettingData['firstClassNum'])
        self.secondClassNumCtrl.SetValue(cueSettingData['secondClassNum'])
        self.baselineCtrl.SetValue(cueSettingData['baselineDuration'])
        self.waitCueCtrl.SetValue(cueSettingData['waitCueDuration'])
        self.dispCueCtrl.SetValue(cueSettingData['dispCueDuration'])
        self.repeatCueCtrl.SetValue(cueSettingData['repeatCue'])
        self.auditoryCue.SetValue(cueSettingData['auditoryIsChecked'])


